/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itschapala.com.dsw2.Dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.itschapala.com.dsw2.modelo.Articulo;

/**
 *
 * @author z
 */
@Stateless
public class ArticuloDao extends AbstractDao<Articulo> implements ArticuloDaoLocal {
    @PersistenceContext(unitName = "Inventario1-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ArticuloDao() {
        super(Articulo.class);
    }

    @Override
    public boolean findDuplicity(Articulo item) {
        //seleccionar  consulta 
        Query q = em.createNamedQuery("Articulo.findDuplicity");
        //poner parametro
        q.setParameter("nombre", item.getNombre());
        q.setParameter("apellidoPaterno", item.getCantidad());
        q.setParameter("apellidoMaterno",item.getCosto());
        q.setParameter("apellidoMaterno",item.getFechaIngreso());
        q.setParameter("apellidoMaterno",item.getIdArticulo());
        q.setParameter("apellidoMaterno",item.getProveedor());
        q.setParameter("apellidoMaterno",item.getUsuario());
        //ejecutar  la  consulta
         return !q.getResultList().isEmpty();
    }
    
}
